package com.haier.controller.manager;

import com.haier.dto.HpAuthorizerConfigDto;
import com.haier.service.IHpAuthorizerConfigService;
import com.haier.vo.ResponseVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 授权配置
 */
@RestController
@RequestMapping(value = "/hipassjava/manager/hpAuthorizer")
public class ManagerHpAuthorizerConfigContoller {
	private static final Logger logger = LoggerFactory.getLogger(ManagerHpAuthorizerConfigContoller.class);
	@Autowired
	private IHpAuthorizerConfigService iHpAuthorizerConfigService;

	/**
	 * 查询分页
	 */
	@RequestMapping(value = "/page", method = RequestMethod.POST)
	public Object page(@RequestBody HpAuthorizerConfigDto dto) {
		try {
			return ResponseVo.success(iHpAuthorizerConfigService.page(dto));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}

	/**
	 * 修改授权人、被授权人
	 */
	@RequestMapping(value = "/editAuthorizer", method = RequestMethod.POST)
	public Object editAuthorizerLevel(@RequestBody HpAuthorizerConfigDto dto) {
		try {
			return iHpAuthorizerConfigService.saveOrUpdateAuthorizer(dto);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}

	/**
	 * 撤销授权
	 */
	@RequestMapping(value = "/cancleAuthorizer", method = RequestMethod.POST)
	public Object cancleAuthorizerLevel(@RequestBody HpAuthorizerConfigDto dto) {
		try {
			return iHpAuthorizerConfigService.cancleAuthorizer(dto);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}

}
